﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FightTheDragon.Managers;

namespace FightTheDragon.Interface
{
    class Cursor : BaseInterfaceObjects
    {
        private string m_Texture;
        public string Texture
        {
            get { return m_Texture; }
            set { m_Texture = value; }
        }
        private Text m_TextToRef;
        public Text TextToRef
        {
            get { return m_TextToRef; }
            set { m_TextToRef = value; }
        }
        private int m_CursorMovement;
        public int CursorMovement
        {
            get { return m_CursorMovement; }
            set { m_CursorMovement = value; }
        }
        private Vector2 m_CenterChar;
        public Vector2 CenterFontHeight
        {
            get { return m_CenterChar; }
            set { m_CenterChar = value; }
        }
        private int m_LineSpacing;
        public int LineSpacing
        {
            get { return m_LineSpacing; }
            set { m_LineSpacing = value; }
        }
        private float m_Width;
        public float Width
        {
            get { return m_Width; }
            set { m_Width = value; }
        }
        private float m_Height;
        public float Height
        {
            get { return m_Height; }
            set { m_Height = value; }
        }
        private Vector2 m_CursorOffset;
        public Vector2 CursorOffset
        {
            get { return m_CursorOffset; }
            set { m_CursorOffset = value; }
        }
        private Vector2 m_StringLength;
        public Vector2 StringLength
        {
            get { return m_StringLength; }
            set { m_StringLength = value; }
        }
        private int m_MinCursor;
        public int MinCursor
        {
            get { return m_MinCursor; }
            set { m_MinCursor = value; }
        }
        private int m_MaxCursor;
        public int MaxCursor
        {
            get { return m_MaxCursor; }
            set { m_MaxCursor = value; }
        }

        public Cursor(float rot, string texture, float scale, Color c, float Rate, Text TextRef, int cursorMin, int cursorMax)
        {
            Rotate = rot;
            Texture2D temp = GlobalContentManager.Instance.Texture(texture);
            m_Texture = texture;
            Scale = scale;
            m_Height = temp.Height;
            m_Width = temp.Width;
            RotationRate = Rate;
            Color = c;
            m_TextToRef = TextRef;
            m_CenterChar = GlobalContentManager.Instance.Font(m_TextToRef.SpriteFont).MeasureString("A");
            m_CenterChar = new Vector2(m_CenterChar.X / 2, m_CenterChar.Y / 2);
            //Change from ExtraText to Text/m_TextToDisplay after making the effects

            m_StringLength = GlobalContentManager.Instance.Font(m_TextToRef.SpriteFont).MeasureString(m_TextToRef.TextToDisplay);
            m_LineSpacing = GlobalContentManager.Instance.Font(m_TextToRef.SpriteFont).LineSpacing;
            m_MinCursor = cursorMin;
            m_MaxCursor = cursorMax;
            m_CursorMovement = cursorMin;
            m_CursorOffset.X = m_TextToRef.Position.X - m_TextToRef.Origin.X - m_Width * Scale;
            m_CursorOffset.Y = (m_TextToRef.Position.Y - m_TextToRef.Origin.Y - m_CenterChar.Y) + (LineSpacing * m_CursorMovement);
            Position = m_CursorOffset;
            Origin = new Vector2(m_Width / 2, m_Height / 2);


        }
        public Cursor()
        {
            Rotate = 0;
            m_Texture = null;
            Scale = 0;
            RotationRate = 0;
            Color = new Color();
            Position = new Vector2();
            Origin = new Vector2();
            m_TextToRef = new Text();
            m_MinCursor = 0;
            m_MaxCursor = 0;
            m_CursorMovement = 0;
            m_CenterChar = new Vector2();
            m_CursorOffset = new Vector2();
        }
        public override void Render()
        {




            GlobalContentManager.Instance.Sprites.Draw(GlobalContentManager.Instance.Texture(m_Texture)
                , Position, null, Color, Rotate * 3.14f / 180, Origin, Scale, 0, 0);


        }

        public override void Update(float gTime)
        {



            if (m_CursorMovement < m_MinCursor)
                m_CursorMovement = m_MaxCursor;
            if (m_CursorMovement > m_MaxCursor)
                m_CursorMovement = m_MinCursor;

            m_CursorOffset.Y = (m_TextToRef.Position.Y - m_TextToRef.Origin.Y - m_CenterChar.Y) + (LineSpacing * m_CursorMovement);
            Position = m_CursorOffset;

            Rotate += RotationRate;
        }

    }
}
